/*********************************************************************************
 *      Copyright:  (C) 2022 Zhang Changxing<ZhangChangxingVIP@163.com>
 *                  All rights reserved.
 *
 *       Filename:  getime.c
 *    Description:  This file 
 *                 
 *        Version:  1.0.0(04/13/2022)
 *         Author:  Zhang Changxing <ZhangChangxingVIP@163.com>
 *      ChangeLog:  1, Release initial version on "04/13/2022 01:33:25 AM"
 *                 
 ********************************************************************************/
#include "getime.h"

/*get datetime and return the latest time*/
double getime(char *datime)
{
	struct 			timeval tv;
	struct 			tm* st;
	static double 	last_time = 0;


	gettimeofday(&tv, NULL);
	last_time = tv.tv_sec;
	st = localtime(&tv.tv_sec);

	if (NULL != datime)
	{ 
		memset(datime, 0, sizeof(datime));
		sprintf(datime, "%04d:%02d:%02d--%02d:%02d:%02d", st->tm_year+1900,\
		st->tm_mon+1, st->tm_mday+1, st->tm_hour+1, st->tm_min+1, st->tm_sec+1);
	}
	
	return last_time;
}